 
 	<?php
		function set_val($obj, $val, $return='echo')
		{
			if(isset($obj))
				if(isset($obj->$val))
					if($return=='echo')
						echo($obj->$val);
					else
						return $obj->$val;
		}
	?>
 
 <link rel="stylesheet" href="<?php echo $this->config->item('css')?>/jquery.multiselect.css"> <!--  -->
 <link rel="stylesheet" href="<?php echo $this->config->item('css')?>/jquery.multiselect.filter.css"> <!--  -->

<script src="<?php echo $this->config->item('js')?>/jquery.multiselect.min.js"></script>
<script src="<?php echo $this->config->item('js')?>/jquery.multiselect.filter.js"></script>

				<div><br>
					<form id="form" class="block-content form" action="<?php echo site_url('previous_event/save')?>" method="post">
						<input type="hidden" id="id" name="id" value="<?php set_val($event,'id')?>" />
						<div class="_100">
							<p><label for="event_name">Event Name</label>
							<input id="event_name" name="event_name" class="required" type="text" value="<?php set_val($event,'event_name')?>" /></p>
						</div>
						
						
						<div class="_50">
							<p><label for="country">Country</label>
							<select name="country" id="country" class="required">
								<option value="">Select Country</option>
								<?php foreach($this->config->item('en_countries') as $key=>$value):?>
									<option <?php if(set_val($event,'country','return')==$key) echo 'selected="selected"';?> value="<?php echo $key?>"><?php echo $value?></option>
								<?php endforeach;?>
							</select>
							</p>
						</div>
						
						<div class="_50">
							<p><label for="city">City</label><input id="city" name="city" class="required" type="text" value="<?php set_val($event,'city')?>" /></p>
						</div>
						
						<div class="_100">
							<p><label for="address">Address</label><textarea id="address" name="address" class="required" rows="2" cols="40"><?php set_val($event,'address')?></textarea></p>
						</div>
						
						<div class="_100">
							<p><label for="event_subject">Event Subject</label>
							<input id="event_subject" name="event_subject" class="required" type="text" value="<?php set_val($event,'event_subject')?>" /></p>
						</div>
						
						<div class="_100">
							<p><label for="seasonal">Seasonal (Type of Event)</label>
							<select name="seasonal" id="seasonal" class="required">
								<option value="">Select Country</option>
								<?php foreach($this->config->item('en_countries') as $key=>$value):?>
									<option <?php if(set_val($event,'seasonal','return')==$key) echo 'selected="selected"';?> value="<?php echo $key?>"><?php echo $value?></option>
								<?php endforeach;?>
							</select>						
						</div>
						
						<div class="_100">
							<p><label for="event_start">Event Starts</label>
							<input id="event_start" name="event_start" class="required" type="text" value="<?php set_val($event,'event_start')?>" /></p>
						</div>
						
						<div class="_100">
							<p><label for="event_end">Event Ends</label>
							<input id="event_end" name="event_end" class="required" type="text" value="<?php set_val($event,'event_end')?>" /></p>
						</div>
						
						<div class="_100">
							<p><label for="company_id">Organisers</label>
							<select name="company_id" id="company_id" class="" onChange="load_contact(this.value)">
								<option value="">Select Company</option>
								<?php foreach($company as $com):?>
									<option <?php if(set_val($event,'company_id','return')==$com->id) echo 'selected="selected"';?> value="<?php echo $com->id?>"><?php echo $com->name?></option>
								<?php endforeach;?>
							</select>							
						</div>
						
						<div class="_100" id="lbl_contact">
							<p><label for="contact_id">Organiser Responsable</label>
							<select name="contact_id" id="contact_id" class="">
								<option value="">Select Contact</option>
							</select>
							</p>
						</div>
						
						<div class="_100">
							<p><label for="notes">Notes</label><textarea id="notes" name="notes" class="" rows="2" cols="40"><?php set_val($event,'notes')?></textarea></p>
						</div>
						
						<div class="_100">
							<p><label for="attendance">Attendance</label><textarea id="attendance" name="attendance" class="" rows="2" cols="40"><?php set_val($event,'attendance')?></textarea></p>
						</div>

						
						
						

						<div class="clear"></div>
						<div class="block-actions">
							<ul class="actions-left">
								<li><a class="button red" id="reset-validate-form" href="javascript:void(0);">Reset</a></li>
							</ul>
							<ul class="actions-right">
								<li><input type="submit" class="button" value="Save!"></li>
							</ul>
						</div>
					</form>

				</div>
				
				
	<script type="text/javascript">
			
	function load_contact(com, con)
	{
		$('#contact_id').html('');
		$.jGrowl("Please Wait<br>While we get the contacts under this company..", { theme: 'information' });
		
		$.post("<?php echo site_url('contact/company_contact/')?>/"+com,
			function(data){
				newdata = $.parseJSON(data);
				if(newdata){
					var selected = '';	
					var options = '<option value="">Select Contact</option>';	
					$.each(newdata, function(index,value){
						if(con==value.id)
							selected = 'selected="selected"';
							
						options+='<option '+selected+' value="'+value.id+'">'+value.name_ar+'</option>';
						selected = '';	
						
					});
					
					
					$('#contact_id').append(options);
					$("#contact_id").multiselect('refresh');
					$("button.ui-multiselect").css('width','200px');
					$(".ui-multiselect-menu").css('width','285px');
					$("#lbl_contact").css('width','200px').effect("highlight", {}, 3000);


				}
				else{
					$.jGrowl("Error! No Contacts in the selected Company", { theme: 'error' });
				}
			});
	}			
		
	$().ready(function() {

		$("#country, #company_id, #contact_id, #seasonal").multiselect({
		   multiple: false,
		   header: "Select an option",
		   noneSelectedText: "Select an Option",
		   selectedList: 1,
		   position: {
			  my: 'left bottom',
			  at: 'left top'
		   },
		   maxWidth: 100,
		   show: "slide",
		   hide: "slide"

		}).multiselectfilter();
		
		$("button.ui-multiselect").css('width','200px');
		$(".ui-multiselect-menu").css('width','285px');
		

		$( "#event_start, #event_end" ).datepicker();
		
		
		
		<?php
		// this should works only on edit
			$id = set_val($event,'id', 'return');
			if($id > 0 && $id!=''):
			?>
			var com = $("#company_id").val();

			<?php foreach($contact as $com):?>
				<?php if(set_val($event,'contact_id','return')==$com->id)?>
					var current = <?php set_val($event,'contact_id')?>;
			<?php endforeach;?>
			load_contact(com,current)
			
		<?php endif;?>
		
		
		
		
		
		/** Submit Form **/
		$("#form").validate({
				rules:{},
				messages: {},
				submitHandler: function(form) {
				   //submit
				$.post("<?php echo site_url('previous_event/save')?>", $("#form").serialize(),
					function(data){
						if(data){
							
							newdata = $.parseJSON(data);
							
							if(newdata.error){
								Gtheme = 'error';
								
								$.each(newdata.msg, function(index) {
									$.jGrowl(newdata.msg[index], { theme: Gtheme,position:'center'  });
								});

							}
							else{
								Gtheme = 'saved';
								$.jGrowl(newdata.msg, { theme: Gtheme,position:'center'  });
								$('.a-z-list').parent().children('.block-content').slideToggle();
								a_z_list();
								temp_id = $("#id").val();
								//clear the folrm
									$("#id").val('');
									$(":input").not(":button, :submit, :reset, :hidden").each(function () {
										this.value = '';
									});
								load_form(temp_id);
							}

						}
						else{
							$.jGrowl("Error!", { theme: 'error' });
						}
					});
				}
			});
		/** End Submit Form **/
		
		});
		
		
    </script>

